package cn.edu.lingnan.servlet;

import cn.edu.lingnan.pojo.Participation;
import cn.edu.lingnan.service.IParticipationService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.util.Collections;


@WebServlet("/admin/updatePart")
public class UpdateParticipation extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1
        String pid = req.getParameter("pid");
        System.out.println("[Debug 080] the participationId is "+pid);
        String studentId = req.getParameter("studentId");
        String competitionId = req.getParameter("competitionId");
        String competitionName = req.getParameter("competitionName");
        String score = req.getParameter("score");
        String rank = req.getParameter("rank");
        String status = req.getParameter("status");

        Participation participation = new Participation();
        participation.setId(Integer.parseInt(pid));
        participation.setStudent_id(Integer.parseInt(studentId));
        participation.setCompetition_id(Integer.parseInt(competitionId));
        participation.setCompetition_name(competitionName);
        participation.setScore(Float.parseFloat(score));
        participation.setCompetition_rank(Integer.parseInt(rank));
        participation.setStatus(Integer.parseInt(status));
//        System.out.println(participation);
        //2
        IParticipationService service = new IParticipationService();
        service.updateParticipation(participation);
        //3
        resp.sendRedirect("/queryAllPart");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
